#ifndef __buzzer_C
#define __buzzer_C

#include "buzzer.h"

/////// 有源蜂鸣器  //////////
////// 策略：高电平 = 蜂鸣器叫; 低电平 = 蜂鸣器不叫 //////
void buzzer_init(){
    GPIO_Config_T     configStruct;    

    RCM_EnableAPB2PeriphClock(buzzer_RCM);	  
    configStruct.mode  = GPIO_MODE_OUT_PP;      
	  configStruct.speed = GPIO_SPEED_50MHz;    
    configStruct.pin   = buzzer_PinId;    
    GPIO_Config(buzzer_PinPort, &configStruct);    
	  	  
    // 初始状态                                
    buz_bit_reset(buzzer_PinId);
}


#if beep_type == beep_APM
// 启动蜂鸣器鸣叫：
void beep_start(uint8_t beep_times_input,uint16_t beep_Tm_input,uint16_t beep_idle_Tm_input){
	  startBeep();
	  beep.beep_start_tm = system_time;
	  beep.beep_step = 1;
	  beep.beep_times = beep_times_input;
	  beep.beep_Tm = beep_Tm_input;
	  beep.beep_idle_Tm = beep_idle_Tm_input;	  	  
}	

void beep_step_run(){
	  if(system_time - beep.beep_start_tm > beep.beep_Tm && beep.beep_step % 2 == 1){
				stopBeep();
			  beep.beep_start_tm = system_time;
				beep.beep_step++;
		}else if(system_time - beep.beep_start_tm > beep.beep_idle_Tm && beep.beep_step % 2 == 0){
			  startBeep();
			  beep.beep_start_tm = system_time;
				beep.beep_step++;
		}
}
#endif

#endif

